<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 *
 * @copyright  Copyright (c) 2009 Maison du Logiciel (http://www.maisondulogiciel.com)
 * @author : Olivier ZIMMERMANN
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
	class Gold_Orderpreparation_Helper_Data extends Mage_Core_Helper_Abstract
{
	
	/*##########################################################################################################################
	############################################################################################################################
	METHODS USED WITH BACKGROUNDTASK MODULE	
	############################################################################################################################
	##########################################################################################################################*/
	
	/**
	 * Notify Shipment
	 *
	 * @param unknown_type $shipmentId
	 */
	public function notifyShipment($shipmentId)
	{
			$shipment = Mage::getModel('sales/order_shipment')->load($shipmentId);
			if ($shipment->getId())
			{
				if (!$shipment->getEmailSent())
				{		
					$shipment->sendEmail(true);
					$shipment->setEmailSent(true)->save();
				}
			}
	}
	
	/**
	 * Notify Invoice
	 *
	 * @param unknown_type $invoiceId
	 */
	public function notifyInvoice($invoiceId)
	{
			$invoice = Mage::getModel('sales/order_invoice')->load($invoiceId);
			if ($invoice->getId())
			{
				if (!$invoice->getEmailSent())
				{
	
					$invoice->sendEmail(true);
					$invoice->setEmailSent(true)->save();
	
				}
			}	
	}
	
	public function setShipmentState($order)
	{
		$shipmentCol = $order->getShipmentsCollection();  
    	$shipmentState= array();
    	if ($shipmentCol)
    	{
    		foreach ($shipmentCol as $shipment)
    		{
			    if(!$shipment->getTracking())
				{
				  $trackingNum = 0;
				}
				else
				{
				  $trackings = explode('<br/>',trim($shipment->getTracking(),'<br/>'));
				  $trackingNum = count($trackings);
				}				
    			$shipmentState[] = $shipment->getIncrementId() . "(<b>T:$trackingNum</b>)";
    		}
			$order->setShipmentState(implode("<br/>", $shipmentState));
    	}
    	
    	return $order;
	}
	
}

?>